package com.usian.mapper;

import com.usian.admin.AdminUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 米西米西
 */
@Mapper
public interface AdminUserMapper {
    @Select("select * from admin_user where account = #{account} and password = #{password}")
    AdminUser login(AdminUser adminUser);

    @Select("select * from admin_user where invitation_code = #{invitationCode}")
    Integer register(AdminUser adminUser);

    @Select("select * from admin_user where id = #{id}")
    AdminUser selectById(Integer id);

    @Insert("insert into admin_user(account,password,invitation_code,start_date,update_date) values(#{account},#{password},#{invitationCode},#{startDate},#{updateDate})")
    void insterCode(AdminUser adminUser);

    @Select("<script>" +
            "SELECT * FROM admin_user" +
            "<where>" +
            "    1=1" +
            "    <if test='account != null and account.trim() != \"\"'> " +
            "        AND account LIKE CONCAT('%', #{account}, '%') " +
            "    </if>" +
            "</where>" +
            "</script>")
    List<AdminUser> findAll(AdminUser adminUser);

}
